<?php

class Arsip{

	private $id;
	private $kd_surat;
	private $pengarsip;
	private $unit_pengarsip;
	private $tgl_pengarsipan;
	private $lokasi;
	
	
	function __construct(){}
	
	function setId($id){
		$this->id = $id;
	}
	
	function setKd_surat($kd_surat){
		$this->kd_surat = $kd_surat;
	}
	
	function setPengarsip($pengarsip){
		$this->pengarsip = $pengarsip;
	}
	
	function setUnitPengarsip($unit_pengarsip){
		$this->unit_pengarsip = $unit_pengarsip;
	}
	
	function setTgl_pengarsipan($tgl_pengarsipan){
		$this->tgl_pengarsipan = $tgl_pengarsipan;
	}
	
	function setLokasi($lokasi){
		$this->lokasi = $lokasi;
	}
	
	function getId(){
		return $this->id;
	}
	
	function getKd_surat(){
		return $this->kd_surat;
	}
	
	function getUnitPengarsip(){
		return $this->unit_pengarsip;
	}
	
	function getPengarsip(){
		return $this->pengarsip;
	}
	
	function getTgl_pengarsipan(){
		return $this->tgl_pengarsipan;
	}
	
	function getLokasi(){
		return $this->lokasi;
	}
}

class Daftar_arsip{
	
	function __construct(){}
	
	function getArsipSMBySM($kd_sm){
		
		$sql="
			select * from arsip_sm where kd_sm = '$kd_sm'
		";
		
		$list_arsip = array();
		
		$data = mysql_query($sql);
		if($data){
			while($row = mysql_fetch_assoc($data)){
			
				$arsip = new Arsip();
				$arsip->setId($row['kd_arsip_sm']);
				$arsip->setKd_surat($row['kd_sm']);
				$arsip->setPengarsip($row['pengarsip_sm']);
				$arsip->setUnitPengarsip($row['unit_pengarsip_sm']);
				$arsip->setLokasi($row['lokasi_sm']);
				$arsip->setTgl_pengarsipan($row['tgl_pengarsipan_sm']);
	
				$list_arsip[] = $arsip;
			}
		}	
		return $list_arsip;
	
	}
	
	
	
	function getArsipSMByPengarsipUnit($pengarsip, $unit){
		
		$sql="
			select * from arsip_sm 
			WHERE
			pengarsip_sm = '$pengarsip' AND
			unit_pengarsip_sm = '$unit' 
		";
		
		$list_arsip = array();
		
		$data = mysql_query($sql);
		if($data){
			while($row = mysql_fetch_assoc($data)){
			
				$arsip = new Arsip();
				$arsip->setId($row['kd_arsip_sm']);
				$arsip->setKd_surat($row['kd_sm']);
				$arsip->setPengarsip($row['pengarsip_sm']);
				$arsip->setLokasi($row['lokasi_sm']);
				$arsip->setTgl_pengarsipan($row['tgl_pengarsipan_sm']);
	
				$list_arsip[] = $arsip;
			}
		}	
		return $list_arsip;
	
	}
	
	function getArsipSMByPengarsipUnitThn($pengarsip, $unit, $thn){
		
		$sql="
			select * from arsip_sm 
			WHERE
			pengarsip_sm = '$pengarsip' AND
			unit_pengarsip_sm = '$unit' AND
			year(tgl_pengarsipan_sm) = '$thn'
		";
		
		$list_arsip = array();
		
		$data = mysql_query($sql);
		if($data){
			while($row = mysql_fetch_assoc($data)){
			
				$arsip = new Arsip();
				$arsip->setId($row['kd_arsip_sm']);
				$arsip->setKd_surat($row['kd_sm']);
				$arsip->setPengarsip($row['pengarsip_sm']);
				$arsip->setLokasi($row['lokasi_sm']);
				$arsip->setTgl_pengarsipan($row['tgl_pengarsipan_sm']);
	
				$list_arsip[] = $arsip;
			}
		}	
		return $list_arsip;
	
	}
	
	function getArsipSKBySK($kd_sk){
		
		$sql="
			select * from arsip_sk where kd_sk = '$kd_sk'
		";
		
		$list_arsip = array();
		
		$data = mysql_query($sql);
		if($data){
			while($row = mysql_fetch_assoc($data)){
			
				$arsip = new Arsip();
				$arsip->setId($row['kd_arsip_sk']);
				$arsip->setKd_surat($row['kd_sk']);
				$arsip->setPengarsip($row['pengarsip_sk']);
				$arsip->setUnitPengarsip($row['unit_pengarsip_sk']);
				$arsip->setLokasi($row['lokasi_sk']);
				$arsip->setTgl_pengarsipan($row['tgl_pengarsipan_sk']);
	
				$list_arsip[] = $arsip;
			}
		}	
		return $list_arsip;
	
	}
	
	function getArsipSKByPengarsipUnit($pengarsip, $unit){
		
		$sql="
			select * from arsip_sk 
			WHERE
			pengarsip_sk = '$pengarsip' AND
			unit_pengarsip_sk = '$unit' 
		";
		
		$list_arsip = array();
		
		$data = mysql_query($sql);
		if($data){
			while($row = mysql_fetch_assoc($data)){
			
				$arsip = new Arsip();
				$arsip->setId($row['kd_arsip_sk']);
				$arsip->setKd_surat($row['kd_sk']);
				$arsip->setPengarsip($row['pengarsip_sk']);
				$arsip->setLokasi($row['lokasi_sk']);
				$arsip->setTgl_pengarsipan($row['tgl_pengarsipan_sk']);
	
				$list_arsip[] = $arsip;
				
			}
		}	
		return $list_arsip;
	
	}
	
	function getArsipSKByPengarsipUnitThn($pengarsip, $unit, $thn){
		
		$sql="
			select * from arsip_sk 
			WHERE
			pengarsip_sk = '$pengarsip' AND
			unit_pengarsip_sk = '$unit' AND
			year(tgl_pengarsipan_sk) = '$thn'
		";
		
		$list_arsip = array();
		
		$data = mysql_query($sql);
		if($data){
			while($row = mysql_fetch_assoc($data)){
			
				$arsip = new Arsip();
				$arsip->setId($row['kd_arsip_sk']);
				$arsip->setKd_surat($row['kd_sk']);
				$arsip->setPengarsip($row['pengarsip_sk']);
				$arsip->setLokasi($row['lokasi_sk']);
				$arsip->setTgl_pengarsipan($row['tgl_pengarsipan_sk']);
	
				$list_arsip[] = $arsip;
				
			}
		}	
		return $list_arsip;
	
	}
	
	function getArsipSMById($id){
		
		$sql="
			select * from arsip_sm where kd_arsip_sm = '$id'
		";
		
		$data = mysql_query($sql);
		if($data){
			while($row = mysql_fetch_assoc($data)){
			
				$arsip = new Arsip();
				$arsip->setId($row['kd_arsip_sm']);
				$arsip->setKd_surat($row['kd_sm']);
				$arsip->setPengarsip($row['pengarsip_sm']);
				$arsip->setUnitPengarsip($row['unit_pengarsip_sm']);
				$arsip->setLokasi($row['lokasi_sm']);
				$arsip->setTgl_pengarsipan($row['tgl_pengarsipan_sm']);
	
			}
		}	
		return $arsip;
	
	}
	
	function getArsipSKById($id){
		
		$sql="
			select * from arsip_sk where kd_arsip_sk = '$id'
		";
		
		$data = mysql_query($sql);
		if($data){
			while($row = mysql_fetch_assoc($data)){
			
				$arsip = new Arsip();
				$arsip->setId($row['kd_arsip_sk']);
				$arsip->setKd_surat($row['kd_sk']);
				$arsip->setPengarsip($row['pengarsip_sk']);
				$arsip->setUnitPengarsip($row['unit_pengarsip_sk']);
				$arsip->setLokasi($row['lokasi_sk']);
				$arsip->setTgl_pengarsipan($row['tgl_pengarsipan_sk']);
	
			}
		}	
		return $arsip;
	
	}
	
	function addArsipSM(Arsip $arsip){
	
		$sql="
		insert into arsip_sm(kd_arsip_sm, kd_sm, pengarsip_sm, unit_pengarsip_sm, tgl_pengarsipan_sm, lokasi_sm)
		values(
		'',
		'".$arsip->getKd_surat()."',
		'".$arsip->getPengarsip()."',
		'".$arsip->getUnitPengarsip()."',
		'".$arsip->getTgl_pengarsipan()."',
		'".$arsip->getLokasi()."'
		)
		";
		//var_dump($arsip);
		$query = mysql_query($sql);
		
	}
	
	function addArsipSK(Arsip $arsip){
	
		$sql="
		insert into arsip_sk(kd_arsip_sk, kd_sk, pengarsip_sk, unit_pengarsip_sk, tgl_pengarsipan_sk, lokasi_sk)
		values(
		'',
		'".$arsip->getKd_surat()."',
		'".$arsip->getPengarsip()."',
		'".$arsip->getUnitPengarsip()."',
		'".$arsip->getTgl_pengarsipan()."',
		'".$arsip->getLokasi()."'
		)
		";
		//var_dump($arsip);
		$query = mysql_query($sql);
		
	}
	
	function editArsipSM(Arsip $arsip_sm){
		$sql="UPDATE arsip_sm SET
		tgl_pengarsipan_sm = '".$arsip_sm->getTgl_pengarsipan()."',
		lokasi_sm = '".$arsip_sm->getLokasi()."'
		WHERE 
		kd_arsip_sm='".$arsip_sm->getId()."'
		";
		$query=mysql_query($sql);
		//var_dump($posisi_surat);
	}
	
	function editArsipSK(Arsip $arsip_sk){
		$sql="UPDATE arsip_sk SET
		tgl_pengarsipan_sk = '".$arsip_sk->getTgl_pengarsipan()."',
		unit_pengarsip_sk = '".$arsip_sk->getUnitPengarsip()."',
		lokasi_sk = '".$arsip_sk->getLokasi()."'
		WHERE 
		kd_arsip_sk='".$arsip_sk->getId()."'
		";
		$query=mysql_query($sql);
		//var_dump($posisi_surat);
	}
	
	
	function deleteArsipSM($id){
		$sql="
		delete from arsip_sm where kd_arsip_sm = '$id'		
		";
		$query = mysql_query($sql);
		return $query;
	}
	
	function deleteArsipSK($id){
		$sql="
		delete from arsip_sk where kd_arsip_sk = '$id'		
		";
		$query = mysql_query($sql);
		return $query;
	}

	
	
	

}